{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import QuantLib as ql"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.Enviroment\n",
    "settings = ql.Settings.instance()\n",
    "evDate = ql.Date(24, 3, 2023)\n",
    "settings.setEvaluationDate(evDate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "September 15th, 2023\n"
     ]
    }
   ],
   "source": [
    "Cal = ql.China()\n",
    "DC360 = ql.Actual360()\n",
    "DC365 = ql.Actual365Fixed()\n",
    "settlementDays = 0\n",
    "refDate = Cal.advance(evDate, settlementDays, ql.Days, ql.Following, False)\n",
    "maturity = ql.Date.nthWeekday(3, ql.Friday, ql.September, 2023)\n",
    "print(maturity)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Date(24,3,2023)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "settings.getEvaluationDate()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "45009\n"
     ]
    }
   ],
   "source": [
    "evDateNum = evDate.serialNumber()\n",
    "print(evDateNum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "March 25th, 2023\n"
     ]
    }
   ],
   "source": [
    "nextDate = evDate + 1\n",
    "print(nextDate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "March 31st, 2023\n"
     ]
    }
   ],
   "source": [
    "nextWeek = evDate + 7\n",
    "print(nextWeek)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "print(evDate.weekday())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Year:  2023\n",
      "Month:  3\n",
      "Day Of Month:  24\n"
     ]
    }
   ],
   "source": [
    "print(\"Year: \", evDate.year())\n",
    "print(\"Month: \", evDate.month())\n",
    "print(\"Day Of Month: \", evDate.dayOfMonth())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "92\n"
     ]
    }
   ],
   "source": [
    "date1 = ql.Date(1, 3, 2022)\n",
    "date2 = ql.Date(1, 6, 2022)\n",
    "diff = date2 - date1\n",
    "print(diff)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Year Fraction of Actual360 is  0.25555555555555554\n",
      "Year Fraction of Actual365Fixed is  0.25205479452054796\n",
      "Year Fraction of Actual30360 is  0.25\n"
     ]
    }
   ],
   "source": [
    "DC360 = ql.Actual360()\n",
    "DC30360 = ql.Thirty360()\n",
    "YF360 = DC360.yearFraction(date1, date2)\n",
    "print(\"Year Fraction of Actual360 is \", YF360)\n",
    "YF365 = DC365.yearFraction(date1, date2)\n",
    "print(\"Year Fraction of Actual365Fixed is \", YF365)\n",
    "YF30360 = DC30360.yearFraction(date1, date2)\n",
    "print(\"Year Fraction of Actual30360 is \", YF30360)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "March 24th, 2023\n",
      "March 24th, 2023\n",
      "September 15th, 2023\n"
     ]
    }
   ],
   "source": [
    "print(evDate)\n",
    "print(refDate)\n",
    "print(maturity)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
